/*
 * @Author: thinkido 4077725@qq.com
 * @Date: 2022-07-07 18:59:50
 * @LastEditors: thinkido 4077725@qq.com
 * @LastEditTime: 2022-07-08 21:51:42
 * @FilePath: \vue3vite-framework\vite.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineConfig, loadEnv, UserConfig, ConfigEnv } from 'vite'

import path from "path";
import vue from '@vitejs/plugin-vue'
import css from 'vite-plugin-css';
import viteSvgIcons from 'vite-plugin-svg-icons';
import { viteMockServe } from 'vite-plugin-mock';
import { quasar, transformAssetUrls } from '@quasar/vite-plugin'

// https://vitejs.dev/config/
export default ({ mode, command }) => {
    // .env.dev 配置前缀必须是 VITE_
    let env = loadEnv(mode, process.cwd());
    console.log('vite.config ', mode, command, env); // 在nodejs项目运行窗口打印
    return defineConfig({
            resolve: {
                alias: {
                    "@": path.resolve(__dirname, "src"),
                    "components": path.resolve(__dirname, "src/components"),
                    "styles": path.resolve(__dirname, "src/styles"),
                    "plugins": path.resolve(__dirname, "src/plugins"),
                    "views": path.resolve(__dirname, "src/views"),
                    "layouts": path.resolve(__dirname, "src/layouts"),
                    "utils": path.resolve(__dirname, "src/utils"),
                    "apis": path.resolve(__dirname, "src/apis"),
                    "dirs": path.resolve(__dirname, "src/directives"),
                },
            },
            server: {
                proxy: {
                    // '/api/': env.VUE_APP_BASE_URL, 
                }
            },
            plugins: [
                vue(),
                css({
                        // css预处理器
                        preprocessorOptions: {
                            scss: {
                                // 引入 var.scss 这样就可以在全局中使用 var.scss中预定义的变量了
                                additionalData: '@import "./src/style/index.scss"'
                            }
                        }            
               }),            
                viteSvgIcons({
                    // Specify the icon folder to be cached
                    iconDirs: [path.resolve(process.cwd(), 'src/icons/svgs')],
                    // Specify symbolId format
                    symbolId: 'icon-[dir]-[name]',
                }),
                viteMockServe({
                    // default，暂未使用。在main.js中启动了。
                    mockPath: 'mock',
                    logger: true,
                    localEnabled: command === 'serve',
                    prodEnabled: command !== 'serve' && false,
                    injectCode: `
                    import { setupProdMockServer } from './mock/mockProdServer';
                    console.log('vite.config.js mock inject in')
                    setupProdMockServer();
                    `,
                    supportTs: false
                }),
                quasar({
                  sassVariables: 'src/styles/quasar-variables.sass'
                })
            ],            
            optimizeDeps: {
                include: [],
                // exclude: ['axios'] 
            },

    })
};